﻿using System;
using System.Collections.Generic;
using System.Text;
using TextEditor.TextDocument.Control;

namespace TextEditor.TextDocument.Action
{
    public class A_SetFont : A_Action
    {
        public override string ActionName()
        {
            return "setfont";
        }

        public override bool Execute()
        {
            using (frmSetFont font = new frmSetFont())
            {
                if (font.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    this.OwnerDocument.Info.DefaulFontSize = font.FontSize;
                    this.OwnerDocument.Info.DefaultFontName = font.Z_fontname;
                    this.OwnerDocument.Info.DefaultEnglishFontName = font.E_fontname;
                }
            }
            return true;
        }

        public override bool UIExecute()
        {
            using (frmSetFont font = new frmSetFont())
            {
                font.SetF1 = this.OwnerDocument.View.DefaultFont.Name;
                font.SetF2 = this.OwnerDocument.View.DefaultEnglishNumFont.Name;
                font.SetF3 = (int)this.OwnerDocument.View.DefaultFont.Size;
                font.ShowDialog();
                if (font.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    this.OwnerDocument.Info.DefaulFontSize = font.FontSize;
                    this.OwnerDocument.Info.DefaultFontName = font.Z_fontname;
                    this.OwnerDocument.Info.DefaultEnglishFontName = font.E_fontname;
                    base.OwnerDocument.RefreshSize();
                    base.OwnerDocument.ContentChanged();
                }
            }
            return true;
        }

        public override bool isEnable()
        {
            return base.myOwnerDocument.CanModify();
        }
    }
}
